package com.hongxun.design.bean;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.hongxun.design.bean.photopassbean.SystemTypeBean;
import com.hongxun.design.mytools.MString;
import com.hongxun.design.mytools.MyLog;

import java.util.List;

/**
 * Created by zerdoor_pc on 2016/6/13.
 */
public class SearchBean {
    public String title;//大类标题
    public boolean isDisplayTitle = true;//是否显示标题
    public int type;//item类型
    public List<SystemTypeBean> beans;//数据元
    public String name;//名字
    public String nameCode;//名字
    public String value;//显示值
    public Object valueCode;//正式值
    public String icon;//图标


    public SearchBean(String nameCode, String title, int type, List<SystemTypeBean> beans, String name, String value, Object valueCode, String icon) {
        this.title = title;
        this.nameCode = nameCode;
        this.type = type;
        this.beans = beans;
        if (beans != null) beans.get(0).code = "0";
        this.name = name;
        this.value = value;
        this.valueCode = valueCode;

        if (valueCode.toString().length() > 0 && beans != null && beans.size() > 0) {
            for (SystemTypeBean s : beans) {
                if (s.getTypecode().equals(valueCode.toString())) {
                    this.value = s.getTypename();
                }
            }
        } else if (valueCode.toString().length() > 0 && MString.owner_unit.equals(nameCode)) {
            try {
                MyLog.L(MString.SUCCESSED+" valueCode ="+ valueCode.toString());

                UnitBean bean =JSON.parseObject(String.valueOf(valueCode), new TypeReference<UnitBean>() {
                });

                this.value = bean.getDepartname();
            }catch (Exception e){}
        }
        this.icon = icon;
    }

    public SearchBean(String title, int type, List<SystemTypeBean> beans, String name, String value, Object valueCode, String icon) {
        this.title = title;
        this.type = type;
        this.beans = beans;
        if (beans != null) beans.get(0).code = "0";
        this.name = name;
        this.value = value;
        this.valueCode = valueCode;
        this.icon = icon;
    }

    public SearchBean(String nameCode, String title, boolean isDisplayTitle, int type, List<SystemTypeBean> beans, String name, String value, Object valueCode, String icon) {
        this.nameCode = nameCode;
        this.title = title;
        this.isDisplayTitle = isDisplayTitle;
        this.type = type;
        this.beans = beans;
        this.name = name;
        this.value = value;
        this.valueCode = valueCode;

        if (valueCode.toString().length() > 0 && beans != null && beans.size() > 0) {
            for (SystemTypeBean s : beans) {
                if (s.getTypecode().equals(valueCode.toString())) {
                    this.value = s.getTypename();
                }
            }
        } else if (valueCode.toString().length() > 0 && MString.design_unit.equals(nameCode)) {
            try {
                MyLog.L(MString.SUCCESSED+" valueCode ="+ valueCode.toString());

                UnitBean bean =JSON.parseObject(String.valueOf(valueCode), new TypeReference<UnitBean>() {
                });

                this.value = bean.getDepartname();
            }catch (Exception e){}
        }
        this.icon = icon;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public boolean isDisplayTitle() {
        return isDisplayTitle;
    }

    public void setIsDisplayTitle(boolean isDisplayTitle) {
        this.isDisplayTitle = isDisplayTitle;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public List<SystemTypeBean> getBeans() {
        return beans;
    }

    public void setBeans(List<SystemTypeBean> beans) {
        this.beans = beans;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Object getValueCode() {
        return valueCode;
    }

    public void setValueCode(Object valueCode) {
        this.valueCode = valueCode;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getNameCode() {
        return nameCode;
    }

    public void setNameCode(String nameCode) {
        this.nameCode = nameCode;
    }


}
